package com.mvc.interceptor;

import com.mvc.ResponseUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * 登录拦截器,只有存在 session 且 已经set login属性时返回true
 */
public class LoginInterceptor implements HandlerInterceptor{
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession(false);
		
		if(session != null){
			Object flag = session.getAttribute("LOGIN_USER");
			if(flag != null){
				return true;
			}
		}
		ResponseUtil.notLogin(response);
		return false;
	}
}
